#ifndef IMAGEITEM_H
#define IMAGEITEM_H

#include <QGraphicsObject>
#include "iplqimage.h"
#include "rawfile.h"

const int EDGEWIDTH = 20;
const int EDGEHEIGHT = 20;

class ImageItem : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit ImageItem(QString *rawFile, int width=640, int height=480, QGraphicsObject *parent = 0);
    
    QRectF boundingRect() const;
    QPainterPath shape() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    bool checked() const;

    int getWidth() const;
    int getHeight() const;
    int getTimeStampInc() const;
    QString getName() const;

    PFCMU::timestamp_t getCurrentTimeStamp() const;
    void setCurrentTimeStamp(PFCMU::timestamp_t timeStamp);

    PFCMU::timestamp_t getMinTimeStamp() const;
    PFCMU::timestamp_t getMaxTimeStamp() const;

    void saveQImage(QString fileName) const;
signals:
    
public slots:
    void onInitTimeStamp(PFCMU::timestamp_t value);
    void onTimeStampUpdated(PFCMU::timestamp_t value);
    void onCamUpdated(int value);

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event);


private:
    bool m_IsChecked;
    //QCheckBox *checkBox;

    PFCMU::timestamp_t getTimeStamp(PFCMU::RAWFile &m_Raw, off64_t m_FrameNumber) const;
    off64_t searchFrame(PFCMU::timestamp_t targetTimeStamp);

    IplQImage *imageData;
    int m_Width;
    int m_Height;
    int m_ImageWidth;
    int m_ImageHeight;
    const off64_t BLOCKSIZE;
    const int TIMESTAMPINC;
    QString *title;
    QString *m_File;

    PFCMU::RAWFile raw;
    int m_CurrentCam;
    PFCMU::timestamp_t m_MinTimeStamp;
    PFCMU::timestamp_t m_MaxTimeStamp;
    off64_t m_FrameCount;
    PFCMU::timestamp_t m_CurrentTimeStamp;
    
};

#endif // IMAGEITEM_H
